﻿/*
 * Created by SharpDevelop.
 * User: ley
 * Date: 5/17/2010
 * Time: 10:17 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

namespace Ley.Common.Validation
{
	public class ValidationRule<TProperty>
	{
		private TProperty _target;
		private Func<TProperty, bool> _ruleIsSatisfied;
		private string _message;
		
		public ValidationRule(TProperty target, Func<TProperty, bool> rule, string message)
		{
			_target = target;
			_message = message;
			_ruleIsSatisfied = rule;
		}
		
		public string ExecuteRule()
		{
			if (!_ruleIsSatisfied(_target))
				return this._message;
			
			return string.Empty;
		}
	}
}
